package fuzSemRules;

import java.util.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.*;

public class SubClassQuicksort {

	private int partition(List list, int begin, int end) {
		
		OntClass ontClass = (OntClass) ((RDFNode)list.get(begin)).as(OntClass.class), temp; 
		int i = begin + 1, j = end;
		while (i <= j) {
			if ( ( (OntClass)((RDFNode)list.get(i)).as(OntClass.class) ).hasSubClass(ontClass) ) 
				++i;
			else if ( ontClass.hasSubClass( (OntClass)((RDFNode)list.get(j)).as(OntClass.class) ) )
					--j;
			else {
				temp  = (OntClass) ((RDFNode)list.get(i)).as(OntClass.class);
				list.set(i, list.get(j));
				list.set(j, temp);
				++i;
				--j;
			}
		}
		temp = (OntClass) ((RDFNode)list.get(begin)).as(OntClass.class);
		list.set(begin, list.get(j));
		list.set(j, temp);
		return j;
	}
	
	public void quicksort(List list, int begin, int end) {
		
		int j;
		if (begin < end) {
			j = partition(list, begin, end);
			quicksort(list, begin, j-1);
			quicksort(list, j+1, end);
		}
		
	}
	
}
